"""
    Author:
    Date: 2019-08-16

    微信管理后台-入口
"""

from django.shortcuts import render

from entities.consts import *
from entities import moment_mgr
from entities import photo_mgr
from entities import profile_mgr
from entities import redis_mgr
from entities import user_mgr
from entities import video_mgr

from .. import helpers
from .. helpers import gma_login_required


@gma_login_required
def search(request):
    """ 用户定位 """
    openid = helpers.get_request_openid(request)
    search_history_data = redis_mgr.get_search_history(openid, 20)

    context = helpers.build_context(request)
    context['search_history_data'] = [x[0].decode('utf-8') for x in search_history_data]
    return render(request, 'gma/entry/entry_search.html', context)


@gma_login_required
def auth(request):
    """ 内容审核 """
    context = helpers.build_context(request)
    # 待审核的主播数量
    context['waiting_auth_user_count'] = user_mgr.get_waiting_auth_user_count_by_status(AUTH_STATUS_WAITING, request)
    # 待审核的视频数量
    context['waiting_auth_video_count'] = video_mgr.get_video_count_by_auth_status(VIDEO_AUTH_STATUS_WAITING, request)
    # 待审核的照片数量
    context['waiting_auth_photo_count'] = photo_mgr.get_photo_count_by_auth_status(PHOTO_AUTH_STATUS_WAITING, request)
    # 待审核的主播资料数量
    context['waiting_auth_profile_count'] = profile_mgr.get_profile_count_by_auth_status(PROFILE_AUTH_STATUS_WAITING, request)
    # 待审核的主播动态数量
    context['waiting_auth_moment_count'] = moment_mgr.get_moment_count_by_auth_status(AUTH_STATUS_WAITING, request)
    return render(request, 'gma/entry/entry_auth.html', context)


@gma_login_required
def security(request):
    """ 安全管理 """
    context = helpers.build_context(request)
    return render(request, 'gma/entry/entry_security.html', context)


@gma_login_required
def market(request):
    """ 运营工具 """
    context = helpers.build_context(request)
    return render(request, 'gma/entry/entry_market.html', context)


@gma_login_required
def promote(request):
    """ 推广管理 """
    context = helpers.build_context(request)
    # 待审核的提现记录数量
    context['waiting_auth_withdraw_count'] = 0
    return render(request, 'gma/entry/entry_promote.html', context)


@gma_login_required
def service(request):
    """ 外部工具 """
    context = helpers.build_context(request)
    return render(request, 'gma/entry/entry_service.html', context)


@gma_login_required
def download(request):
    """ 产品下载 """
    context = helpers.build_context(request)
    return render(request, 'gma/entry/entry_download.html', context)


@gma_login_required
def system(request):
    """ 系统设置 """
    context = helpers.build_context(request)
    return render(request, 'gma/entry/entry_system.html', context)


@gma_login_required
def app(request):
    """ APP配置 """
    context = helpers.build_context(request)
    return render(request, 'gma/entry/entry_app.html', context)


if __name__ == '__main__':
    print('ok')

